package com.swordxu.yim.server.msgcoder;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;

import java.nio.charset.Charset;
import java.util.List;

/**
 * 客户端消息解码类
 * Created by user063 on 2014/12/26.
 */
public class ClientMessageDecoder extends MessageToMessageDecoder<ByteBuf> {
    private final Charset charset;

    public ClientMessageDecoder() {
        this(Charset.defaultCharset());
    }

    public ClientMessageDecoder(Charset charset) {
        if (charset == null) {
            throw new NullPointerException("charset");
        }
        this.charset = charset;
    }

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf msg, List<Object> out) throws Exception {
//        String message = msg.toString(charset);
//        RequestBody rb = (RequestBody) JSON.parseObject(message, RequestBody.class);
//        out.add(rb);
        out.add(msg.toString(charset));
    }
}
